package com.example.group_20.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.group_20.entity.Group;
import com.example.group_20.entity.Students;
import com.example.group_20.entity.Teachers;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: 栋
 * @data: 2023/8/11
 * @descriptions:
 */
@Mapper
public interface GroupMapper extends BaseMapper<Group> {

    @Select("select * from `group` where group_id=#{group_id}")
    public Group findByid(int group_id);

    @Select("select * from `group` where t_id=#{t_id}")
    public List<Group> findByTid(String t_id);

    @Select("select * from `group` where t_id=#{t_id}")
    @Results(
            {
                    @Result(column = "group_id",property = "group_id"),
                    @Result(column = "s_id",property = "s_id"),
                    @Result(column = "s1_id",property = "s1_id"),
                    @Result(column = "s2_id",property = "s2_id"),
                    @Result(column = "s3_id",property = "s3_id"),
                    @Result(column = "s4_id",property = "s4_id"),
                    @Result(column = "s5_id",property = "s5_id"),
                    @Result(column = "s6_id",property = "s6_id"),
                    @Result(column = "t_id",property = "t_id"),
                    @Result(column = "number",property = "number"),
                    @Result(column = "group_id",property = "students",javaType = List.class,
                        many = @Many(select = "com.example.group_20.mapper.StudentsMapper.findByGroup")),
            }
    )
    public List<Group> findByGroupAndStudents(String t_id);

    @Select("select * from `group`")
    @Results(
            {
                    @Result(column = "group_id",property = "group_id"),
                    @Result(column = "s_id",property = "s_id"),
                    @Result(column = "s1_id",property = "s1_id"),
                    @Result(column = "s2_id",property = "s2_id"),
                    @Result(column = "s3_id",property = "s3_id"),
                    @Result(column = "s4_id",property = "s4_id"),
                    @Result(column = "s5_id",property = "s5_id"),
                    @Result(column = "s6_id",property = "s6_id"),
                    @Result(column = "t_id",property = "t_id"),
                    @Result(column = "number",property = "number"),
                    @Result(column = "group_id",property = "students",javaType = List.class,
                            many = @Many(select = "com.example.group_20.mapper.StudentsMapper.findByGroup")),
                    @Result(column = "t_id",property = "teachers",javaType = Teachers.class,
                            many = @Many(select = "com.example.group_20.mapper.TeacherMapper.findByid")),
            }
    )
    public List<Group> findAll();

//    @Insert("insert into `group` (group_id,s_id,s1_id,s2_id,s3_id,s4_id,s5_id,s6_id,t_id,number) values (#{group_id},#{s_id},#{s1_id},#{s2_id},#{s3_id},#{s4_id},#{s5_id},#{s6_id},#{t_id},#{number})")
    @Insert("insert into `group` (group_id,number) values (#{group_id},#{number})")
    public int addGroup(Group group);

    @Update("update `group` set group_id=group_id-1 where group_id>#{group_id}")
    public int updateGroupId(int group_id);

}
